package xim

import (
	"time"

	"gitee.com/xiaoyutab/xgotool/optional/xlog"
	"gitee.com/xiaoyutab/xgotool/xerror"
)

// IM设备心跳记录
//
//	der_id	设备ID
func Heartbeat(der_id uint) error {
	if _default.DB == nil {
		return xerror.New("数据库未连接")
	}
	err := _default.DB.Table(_default.UserDerviceTable).
		Where("id", der_id).
		Select("is_login", "last_send_time").
		Updates(&ImUserDervice{
			IsLogin:      1,
			LastSendTime: time.Now().Format(time.DateTime),
		}).
		Error
	if err != nil {
		return xlog.AE("设备心跳维持失败", err)
	}
	return nil
}
